package com.cqw.service;

import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-05-06 16:16
 * @Description:
 */
@Service
public class FastDfsFileServiceImpl implements FileService {


    @Value("${fdfs.domain}")
    private String domain;

    @Resource
    private FastFileStorageClient fastFileStorageClient;


    @Override
    public String uploadFile(MultipartFile file) throws IOException {
        StorePath storePath = fastFileStorageClient.uploadFile(file.getInputStream(),
                file.getSize(),
                FilenameUtils.getExtension(file.getOriginalFilename()),
                null);
        return domain + "/" + storePath.getFullPath();
    }
}
